﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.NetworkInformation;
using System.Windows.Forms;
using System.IO;    
using System.Collections;

namespace NetworkScannerC
{
    class computerScan
    {
        public static void checkConnectivity(String server)
        {
            //This will check that the IP is responding to pings
            Ping ipPing = new Ping();
            PingReply ipPingReply;
            ipPingReply = ipPing.Send(server);
            if (ipPingReply.Status.ToString() == "Success")
            {
                MessageBox.Show("YAY IT WORKED");
            }
            else
            {
                //what to do if server doesnt respond to pings
            }
        }
        public static ArrayList sambaList(String path)
        {
            //Scan the samba shares for files
            ArrayList sambaFiles = new ArrayList();
            DirectoryInfo directoryPath = new DirectoryInfo(path);
            try
            {
                FileInfo[] files = directoryPath.GetFiles();
                DirectoryInfo[] directorys = directoryPath.GetDirectories();

                foreach (FileInfo file in files)
                {
                    //Go Through Each File
                    sambaFiles.Add(String.Format("{0}", file.FullName));
                }
                foreach (DirectoryInfo directory in directorys)
                {
                    //Go Through Each Directory
                    foreach (String file in sambaList(directory.FullName))
                    {
                        //Add The Files From The Folder One Down
                        sambaFiles.Add(String.Format("{0}", file));
                    }
                }
            }
            catch (DirectoryNotFoundException dnfe)
            {
                MessageBox.Show(dnfe.ToString());
            }
            catch (UnauthorizedAccessException uae)
            {
                MessageBox.Show("ACCESS DENIED FROM " + path);
            }
            catch (PathTooLongException ptle)
            {
                MessageBox.Show("PATH TO LONG " + ptle.Message);
            }
            return sambaFiles;
        }
    }
}
